package com.kitty.game.gm.handler;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.equip.message.RespNotifyMiscEx;
import com.kitty.game.friend.model.RoleView;
import com.kitty.game.gm.GmService;
import com.kitty.game.player.PlayerService;
import com.kitty.game.role.model.Role;
import com.kitty.game.team.model.Team;
import com.kitty.game.team.service.TeamService;
import com.kitty.mina.message.MessagePusher;

public class GmQuitTeam implements GMFather {
    @Override
    public boolean handle(Role aaa, String content) {
        GmService gmService = SpringUtils.getBean(GmService.class);
        content = gmService.replaceName(content);
        long uid = gmService.getUidByName(content);
        PlayerService playerService = SpringUtils.getPlayerService();
        Role role = playerService.getPlayerBy(uid);
        if (role == null) {
            MessagePusher.pushMessage(aaa, new RespNotifyMiscEx("玩家不存在"));
            return true;
        }
        TeamService teamService = SpringUtils.getTeamService();
        Team team = teamService.getTeam(role.getRoleId());
        if (team == null) {
            MessagePusher.pushMessage(aaa, new RespNotifyMiscEx("玩家没有队伍"));
            return true;
        }
        teamService.leave(new RoleView(uid), true);
        MessagePusher.pushMessage(aaa, new RespNotifyMiscEx("队伍踢出玩家成功"));
        return true;
    }
}
